var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;
if($("#year").val()=="undefined"||$("#year").val()==''){
    $("#year").val(new Date().getFullYear());
}
$.ajax({
    type: "post",
    data: {"industryId":$("#industryId").val(),"year":$("#year").val()},
    url: "/report/getReportDate",
    dataType: "json",
    success: function (data) {
        if (data ==[]){
            layer.alert("该年份还没有数据。");
        }
        option = {
            title: {
                text: $("#industryName").val(),
                subtext: '',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'left'
            },
            series: [
                {
                    name: 'Access From',
                    type: 'pie',
                    radius: '50%',
                    data: data,
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };

        option && myChart.setOption(option);

        //再画个表格
        for (var i =0 ;i<data.length;i++){
            var sHtml = "<tr>";
            sHtml += "<td>"+data[i].name+"</td>";
            var money = data[i].value ;
            var obj = data[i].extendsMap;
            if(money == null){
                money = 0 ;
            }
            sHtml += "<td>"+obj.market_requirement+"</td>";
            sHtml += "<td>"+money+"</td>";
            sHtml += "<td>"+Number(obj.market_share).toFixed(2)+"%</td>";
            sHtml += "<td>"+obj.sale_target+"</td>";
            sHtml += "<td>"+Number(obj.sale_completion).toFixed(2)+"%</td>";
            sHtml += "<td>"+obj.last_year_sales+"</td>";
            sHtml += "<td>"+Number(obj.growth_rate).toFixed(2)+"%</td>";
            if (data.extendsMap==null) {
                 sHtml += "<td><a class='layui-btn layui-btn-norma layui-btn-xs' href='/report/reportView?industryId="+data[i].id+"&industryName="+data[i].name+"&year="+$("#year").val()+"'>详细</a></td>";
            }
            sHtml += "</tr>";
            $("#mainTable").append(sHtml);
        }


    }
})


    layui.use(['table','laydate'], function(){
        var laydate = layui.laydate;
        var table = layui.table;
        form = layui.form;
        //执行一个laydate实例
        laydate.render({
            elem: '#year' //指定元素
            ,type: 'year'
        });

    })
